<?php
class Category
{
	private $db;

	public function __construct($db)
	{
		$this->db = $db;
	}

	/**
	 * 获取帖子分类
	 */
	public function getPostCategories()
	{
		try {
			$stmt = $this->db->query("SELECT * FROM categories ORDER BY id ASC");
			return $stmt->fetchAll(PDO::FETCH_ASSOC);
		} catch (PDOException $e) {
			error_log("[Category Model] 攻略分类查询错误: " . $e->getMessage());
			throw new Exception("获取攻略分类失败");
		}
	}

	/**
	 * 获取话题分类
	 */
	public function getTopicsCategories()
	{
		try {
			$stmt = $this->db->query("SELECT * FROM topics_categ ORDER BY category_id ASC");
			return $stmt->fetchAll(PDO::FETCH_ASSOC);
		} catch (PDOException $e) {
			error_log("[Category Model] 讨论分类查询错误: " . $e->getMessage());
			throw new Exception("获取讨论分类失败");
		}
	}
}
?>